home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 015a / swap300.zip / SWAPTEST.C < prev    next >
C/C++ Source or Header  |  1990-10-04  |  3KB  |  88 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5.  
  6. #include "swap.h"
  7.  
  8. /*
  9.  *    This program is an example of how to use swap() to swap out the
  10.  *    current program, execute another in its place, then restore the
  11.  *    original program.  It should work with Turbo C (all versions),
  12.  *    Turbo C++ 1.0, and Microsoft C 5.10.  It should work fine for the
  13.  *    Small and Medium models of Microsoft C 6.00 (see SWAP.DOC)
  14.  *
  15.  */
  16.  
  17. int swap_return;
  18. unsigned char exec_return;
  19. unsigned char *comspec;
  20. unsigned int dos_ptr;
  21.  
  22. main (int argc, char *argv[])
  23.    {
  24.  
  25.    printf ("Hello--we are now in SWAPTEST.  We are about to execute a DOS shell.\n\n");
  26.  
  27.    if (!xms_installed())
  28.       printf ("No ");
  29.    printf ("XMS driver detected.\n");
  30.  
  31.    if (!ems4_installed())
  32.       printf ("No ");
  33.    printf ("EMS 4.0 driver detected.\n");
  34.  
  35.  
  36. /*
  37.  * Now allocate another DOS block for this program, to demonstrate
  38.  *  new capability of SWAP 3.00 to swap all DOS blocks owned by a program
  39.  *
  40.  * Use _dos_allocmem() for Microsoft C 5.10 and 6.00,
  41.  * use allocmem() for Turbo C++ 1.0 and Turbo C 2.0.
  42.  * Both functions use same parameters.
  43.  * SWAP.ASM must be assembled WITHOUT /DNoFrag for this to work.
  44.  * Allocate a DOS block of 1024 paragraphs (16K bytes).
  45.  */
  46.    _dos_allocmem (1024, &dos_ptr);
  47. /* allocmem (1024u, &dos_ptr); */
  48.  
  49.    printf ("\n** Type EXIT to return to SWAPTEST **\n");
  50.  
  51.    comspec = getenv ("COMSPEC");
  52.  
  53.    swap_return = swap (comspec, "", &exec_return, "swaptest.fil");
  54.  
  55.    printf ("\n\nBack in SWAPTEST now.\n\n");
  56.  
  57.    switch (swap_return)
  58.       {
  59.       case SWAP_OK:        printf ("Successful, executed program returned %d.\n", (int)exec_return);
  60.                            break;
  61.  
  62.       case SWAP_NO_SHRINK: printf ("Unable to shrink DOS memory block.\n");
  63.                            break;
  64.  
  65.       case SWAP_NO_SAVE:   printf ("Unable to save program to memory or disk.\n");
  66.                            break;
  67.  
  68.       case SWAP_NO_EXEC:   printf ("DOS EXEC call failed.  Error is %d: ", (int)exec_return);
  69.                            switch (exec_return)
  70.                               {
  71.                               case BAD_FUNC:       printf ("Bad function.\n");                        break;
  72.                               case FILE_NOT_FOUND: printf ("Program file not found.\n");              break;
  73.                               case ACCESS_DENIED:  printf ("Access to program file denied.\n");       break;
  74.                               case NO_MEMORY:      printf ("Insufficient memory to run program.\n");  break;
  75.                               case BAD_ENVIRON:    printf ("Bad environment.\n");                     break;
  76.                               case BAD_FORMAT:     printf ("Bad format.\n");                          break;
  77.                               default:             printf ("Unexpected error code #%d (decimal).\n", (int)exec_return);
  78.                                                    printf ("Consult DOS technical reference manual.\n");
  79.                                                    break;
  80.  
  81.                               }
  82.       }
  83.  
  84.    return (0);
  85.  
  86.    }
  87.  
  88.